package com.jming.jike.controller.front;

import com.jming.jike.common.PageResult;
import com.jming.jike.common.ResponseResult;
import com.jming.jike.common.ValidatorGroup;
import com.jming.jike.dto.BaseDTO;
import com.jming.jike.dto.front.PayDTO;
import com.jming.jike.service.front.FrontOrdersService;
import com.jming.jike.vo.front.OrdersDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author jinming.zhang
 * @version 0.0.1
 * @date 2022/05/10
 */
@RestController
@RequestMapping("/frontOrders")
@Api(tags = "前台订单相关接口", value = "/frontOrders")
public class FrontOrdersController {

    @Resource
    private FrontOrdersService frontOrdersService;

    @PutMapping("/createOrders")
    @ApiOperation(value = "去结算", notes = "去结算", produces = "application/json", httpMethod = "PUT")
    public ResponseResult<String> createOrders() {

        return ResponseResult.success(frontOrdersService.createOrders());
    }

    @PutMapping("/pay")
    @ApiOperation(value = "支付(支付成功返回订单号)", notes = "支付(支付成功返回订单号)", produces = "application/json", httpMethod = "PUT")
    public ResponseResult<String> pay(@RequestBody @Validated(ValidatorGroup.Update.class) PayDTO payDTO) {

        return ResponseResult.success(frontOrdersService.pay(payDTO));
    }

    @PutMapping("/cancelOrder/{orderId}")
    @ApiOperation(value = "取消订单", notes = "取消订单", produces = "application/json", httpMethod = "PUT")
    public ResponseResult<Boolean> cancelOrder(@PathVariable("orderId") String orderId) {

        return ResponseResult.success(frontOrdersService.cancelOrder(orderId));
    }

    @GetMapping("/pageOrders")
    @ApiOperation(value = "分页查询订单列表(每页默认10条)", notes = "分页查询订单列表(每页默认10条)", produces = "application/json", httpMethod = "GET")
    public ResponseResult<PageResult<OrdersDetailVO>> pageOrders(BaseDTO baseDTO) {

        return ResponseResult.success(frontOrdersService.pageOrders(baseDTO.getPageIndex(), baseDTO.getPageSize()));
    }

    @GetMapping("/orderDetail/{orderId}")
    @ApiOperation(value = "查询订单详情", notes = "查询订单详情", produces = "application/json", httpMethod = "GET")
    public ResponseResult<OrdersDetailVO> orderDetail(@PathVariable("orderId") String orderId) {

        return ResponseResult.success(frontOrdersService.orderDetail(orderId));
    }

}
